package dal.object;

import gui.event.Collision;
import gui.event.GameController;

import java.awt.Graphics;
import java.awt.image.BufferedImage;

import dal.FileIO;

public class Card extends Rock {
	protected static final BufferedImage card = FileIO.readPic(path + "kartya.png");;
	private static final BufferedImage top = FileIO.readPic(path + "fedel.png");
	private boolean finalized = false;
	protected BufferedImage fig;
	
	public Card(){
		super();
	}
	
	public void touch(Collision cld){				
		cld.rockCollision();
		
		if(!finalized && img != fig) {
			setVisible(true);
			GameController.setCard(this);
		}
	}
	
	public void impact(Collision cld){
		touch(cld);
	}
	
	public void drawObject(Graphics g){
		if(finalized || img == fig){
			img = card;
			super.drawObject(g);
			img = fig;
			super.drawObject(g);
		} else {
			img = card;
			super.drawObject(g);
			img = top;
			super.drawObject(g);
		}
	}
	
	/**
	 * @param visible
	 * 	sets the visibility of this object
	 */
	public void setVisible(boolean visible){
		if(visible) {
			img = fig;
		} else {
			img = top;
		}
		
		super.repaint();
	}

	/**
	 * finalizes this object visibility
	 */
	public void finalizeCard() {
		finalized = true;
	}
}
